import os

from gis.common.jsonlogger import JsonFormatter

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

SECRET_KEY = 'n)-&0h&#yoy9w!36joykw#-hq12vg!63khct0*9c-4@_n@qu1o'

DEBUG = True

ALLOWED_HOSTS = ['*']

INSTALLED_APPS = [
    'itpay.core.agency',
    'itpay.core.admin_ext',
    'itpay.core.mch',
    'itpay.core.recharge_order',
    'itpay.core.sys',
    'gis.common.timer',
    'gis.admin.apps.AdminConfig',
    'django.contrib.sessions',
    'test_without_migrations',
]

MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'itpay.server_admin.base.middleware.TrackLoggerMiddleware',
    'gis.common.django_ext.middleware.ApiMiddleware',
    'gis.common.django_ext.middleware.OperationLogMiddleware',
]

TASK_HANDLERS = ['itpay.core.recharge_order.order_service.TransOrderHandler',
                 'itpay.core.recharge_order.order_service.OrderTimeOutHandler',
                 'itpay.core.recharge_order.sms_recharge_service.MatchRechargeOrderHandler',
                 'itpay.core.recharge_order.recharge_comment_service.AutoCommentHandler',
                 'itpay.core.recharge_order.order_service.OrderChaseFrozenHandler',
                 'itpay.core.sys.export_service.ExportHandler',
                 ]

ROOT_URLCONF = 'itpay.server_admin.urls'

LANGUAGE_CODE = 'zh-cn'

TIME_ZONE = 'Asia/Chongqing'

USE_I18N = False

USE_L10N = False

USE_TZ = False

FIXTURE_DIRS = [BASE_DIR + '/tests/gis/admin/fixtures/']

# session有效期12小时
SESSION_COOKIE_AGE = 12 * 60 * 60

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            'format': '%(levelname)s %(asctime)s %(message)s'
        },
        'json_stat': {
            '()': JsonFormatter,
            'format': '%(message)s'
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
        'file': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': '/var/log/itpay_new_admin/itpay_new_admin.log',
            'formatter': 'simple'
        },
        'maestro_file': {
            'level': 'INFO',
            'class': 'logging.handlers.WatchedFileHandler',
            'filename': '/var/log/itpay_new_admin/maestro.json',
            'formatter': 'json_stat'
        },
    },
    'root': {
        'level': 'DEBUG',
        'handlers': ['console', 'file'],
    },
    'loggers': {
        'maestro': {
            'handlers': ['maestro_file'],
            'level': 'INFO',
            'propagate': False
        }
    },
}

SAFE_DOG_CONFIG = {
    "api_domain": "103.230.241.52:8888",
    "app_key": "ERapDtTUwR6310QRzTa5JJBik46f9z6-WnpD3WHX",
    "app_secret": "L52VzPznZr5KfkRTeWgqBuu1sdkENaEMWIGnmq5n",
    "use_https": False,
}

try:
    from itpay.conf.server import *
except ImportError:
    import logging

    logging.warn('no env specified conf loaded, use default.')
    pass

try:
    from .env_settings import *
except ImportError:
    import logging

    logging.warn('no env specified settings loaded, use default.')
    pass
